// pages/shop/qrscene.js
//var QRCode = require('../../utils/weapp-qrcode.js')
//var qrcode;
var memberUtil = require('../../utils/memberUtil');
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    showQR:'',
    imagesUrl: app.globalData.baseImageUrl
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that=this;
    that.setData({
      userInfo: wx.getStorageSync("loginUserInfo").userInfo==undefined?"":wx.getStorageSync("loginUserInfo").userInfo
    });
    //memberUtil.shareDL(app,options,"2",that);

    if(that.data.userInfo.id==undefined) {
      memberUtil.getLogin(app,0,1,that,1);
    }else{
      that.erweima();
    }

  },
  erweima:function(){
    var that=this;
    var shareMemberIdJson = { shareMemberId:that.data.userInfo.id};
      wx.request({
        data:JSON.stringify(shareMemberIdJson),
        url: app.globalData.baseUrl +'/qrcode/getShareORCodeURL',
        header: app.globalData.headerPost,
        method: 'POST',
        success:function(res){
          if (res.statusCode==200){
            app.globalData.loginUserInfo.erweimaUrl=app.globalData.baseUrl+"/"+res.data;
            wx.setStorageSync("loginUserInfo", app.globalData.loginUserInfo);
            that.setData({
              showQR: app.globalData.baseUrl+"/"+res.data
            })
          }
        },
        fail:function(res){
          console.log("小程序二维码失败" + res);
        }
      })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function (res) {
    return {
      title: '我的二维码',
      path: "/pages/shop/shareSuccess?parentId=" + this.data.userInfo.id + "&enterType=0",
      imageUrl: app.globalData.loginUserInfo.erweimaUrl
    }
  }
})